var MongoClient = require('mongodb').MongoClient;
var DB_CONN_STR = 'mongodb://127.0.0.1:27017/mdb';
 
var insertData = function(db, callback) {  
    //连接到表 site
    var collection = db.collection('itembox');
    //插入数据
    // var data = {
    //     id : 1,
    //     png : "wawa1.png",
    //     pickmoney : 19,
    //     pickProbability : 5,
    //     addProbability : 5
    // };


    var data ={
        "ItemGroup" : 1,
        "Group1" : {
            "line1" : {
                "pos" : [
                    0
                ],
                "id" : [
                    1
                ],
                "pickProbability" : [
                    5
                ],
                "addProbability" : [
                    5
                ]
            },
            "line2" : {
                "pos" : [
                    -100,
                    100
                ],
                "id" : [
                    1,
                    1
                ],
                "pickProbability" : [
                    5,
                    5
                ],
                "addProbability" : [
                    5,
                    5
                ]
            },
            "line3" : {
                "pos" : [
                    -150,
                    0,
                    150
                ],
                "id" : [
                    1,
                    1,
                    1
                ],
                "pickProbability" : [
                    5,
                    5,
                    5
                ],
                "addProbability" : [
                    5,
                    5,
                    5
                ]
            }
        }
    }

    collection.insert(data, function(err, result) { 
        if(err)
        {
            console.log('Error:'+ err);
            return;
        }     
        callback(result);
    });
}
 
MongoClient.connect(DB_CONN_STR, function(err, db) {
    console.log("连接成功！");
    insertData(db, function(result) {
        console.log(result);
        db.close();
    });
});